///文件工具类
class FileUtil {
  ///获取temp文件地址
  static String getTempFilePath(String filePath) {
    if (filePath.isEmpty) return "";

    var index = filePath.lastIndexOf(".");
    if (index == -1) return "";

    var tempPath = filePath.replaceRange(index, filePath.length, ".temp");
    return tempPath;
  }

  // 从路径中获取文件名字
  static String getFullFileName(String filePath) {
    if (filePath.isEmpty) return "";

    var index = filePath.lastIndexOf("/");
    if (index == -1) return "";
    String fileName = filePath.substring(index + 1, filePath.length);
    return fileName;
  }

  //获取文件名称
  static String getFileName(String filePath) {
    if (filePath.isEmpty) return "";

    var frontIndex = filePath.lastIndexOf("/");
    var behindIndex = filePath.lastIndexOf(".");
    if (frontIndex == -1 || behindIndex == -1) return "";
    String fileName = filePath.substring(frontIndex + 1, behindIndex);
    return fileName;
  }

  //获取文件格式  后缀 .jpg
  static String getFileFormat(String filePath) {
    if (filePath.isEmpty) return "";

    var index = filePath.lastIndexOf(".");
    String fileFormat = filePath.substring(index + 1, filePath.length);
    return fileFormat;
  }
}
